package com.cjj2016.cjj.mynestedscrolldemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cjj2016.cjj.mynestedscrolldemo.widget.ElemeDetailView;

public class ElemeActivity extends AppCompatActivity {

    private RecyclerView recyclerView;

    private TextView edv_title;

    private  ElemeDetailView elemeDetailView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_eleme);

        recyclerView = (RecyclerView) findViewById(R.id.rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(new MyAdapter());


        edv_title = (TextView) findViewById(R.id.edv_title);

        elemeDetailView = (ElemeDetailView) findViewById(R.id.elemeView);
        elemeDetailView.setMylistener(new ElemeDetailView.MyContentPostionListener() {
            @Override
            public void onContentPositonChange(float fraction) {
                //监听edv_content的位置改变，改变edv_title的透明度
                edv_title.setAlpha(1-fraction);
            }
        });

    }


    class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder>{

        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View itemview = LayoutInflater.from(ElemeActivity.this).inflate(R.layout.list_item,parent,false);

            return new MyViewHolder(itemview);
        }

        @Override
        public void onBindViewHolder(MyViewHolder holder, int position) {
            holder.itemtv.setText("物品"+ position);
        }

        @Override
        public int getItemCount() {
            return 30;
        }



        class MyViewHolder extends RecyclerView.ViewHolder{
             TextView itemtv;

            public MyViewHolder(View itemView) {
                super(itemView);
                itemtv = (TextView) itemView.findViewById(R.id.tv_list_item);
            }
        }

    }


}
